package com.peng.leetcode.greedy;

/**
 * IsSubsequence
 * <p>
 * 392. 判断子序列
 *
 * @author: lupeng6
 * @create: 2021/2/1 14:36
 */
public class IsSubsequence {

    public static void main(String[] args) {
        String s = "abc", t = "ahbgdc";
        System.out.println(new IsSubsequence().isSubsequence(s, t));
    }

    public boolean isSubsequence(String s, String t) {
        int i = 0, j = 0;
        int sLen = s.length(), tLen = t.length();
        while (i < sLen && j < tLen) {
            if (s.charAt(i) == t.charAt(j)) {
                i++;
            }
            j++;
        }
        return i == sLen;
    }
}
